#!/usr/bin/env python
# encoding: utf-8

import json, time, base64, zlib, sys, os

img = open(sys.argv[1],'rb').read()

d = {
    "board_id": int(9),
    "magic": "APJFWv1",
    "description": "Firmware for a STM32F427xx board",
    "image": base64.b64encode(zlib.compress(img,9)).decode('utf-8'),
    "build_time": int(time.time()),
    "summary": "fmuv3",
    "version": "0.1",
    "image_size": len(img),
    "git_identity": "ecbe67a0",
    "board_revision": 0
}

apj_file = sys.argv[1].replace(".bin", ".apj")
if os.path.exists(apj_file):
	os.remove(apj_file)
f = open(apj_file, "w")
f.write(json.dumps(d, indent=4))
f.close()

if os.path.exists(apj_file):
	print "生成成功: " + apj_file
else:
	print "生成失败: " + apj_file

